package com.starlink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starlink.model.domain.ShoppingCartOrderDetailsDO;
import com.starlink.model.request.ShoppingCartOrderDetailsRequest;
import com.starlink.model.vo.mall.MallOrderCarCancelListVO;
import com.starlink.model.vo.mall.MallOrderDetailListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@Repository
public interface ShoppingCartOrderDetailsMapper extends BaseMapper<ShoppingCartOrderDetailsDO> {
    ShoppingCartOrderDetailsDO selectDOById(Long id);
    List<ShoppingCartOrderDetailsDO> selectDOList(ShoppingCartOrderDetailsDO shoppingCartOrderDetails);
    int insertDO(ShoppingCartOrderDetailsDO shoppingCartOrderDetails);
    int batchInsertDO(List<ShoppingCartOrderDetailsDO> shoppingCartOrderDetailsDOList);
    int updateDO(ShoppingCartOrderDetailsDO shoppingCartOrderDetails);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from shopping_cart_order_details",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") ShoppingCartOrderDetailsRequest param);
    @Select({"<script>",
            "   select * from shopping_cart_order_details",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ShoppingCartOrderDetailsDO> pageQuery(@Param("param") ShoppingCartOrderDetailsRequest param, @Param("limit") int limit, @Param("offset") long offset);

    List<Map<String, Long>> selectQuantity(@Param("orderId") Long orderId,@Param("list") List<Long> carOrderIds);

    List<MallOrderCarCancelListVO> selectSpecificationId(@Param("orderId")Long orderId);

    void deleteCarOrderDetaile(@Param("orderId")Long orderId);

    MallOrderDetailListVO selectCarOrderDetail(@Param("orderId")Long orderId);

    MallOrderCarCancelListVO selectDataInfoByAId(@Param("key") Long key,@Param("orderId")Long orderId);

    void updateIsRefunds(@Param("orderId")Long orderId, @Param("articlesId")Long articlesId);

    List<MallOrderCarCancelListVO> selectSpecificationIdByOrderId(@Param("orderId")Long orderId);

    void deletedByOrderIds(String[] toStrArray);

    List<Long> selectInventoryBySpecificationId(@Param("specificationId")Long specificationId);
}
